﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public enum UnitCamp
{
    Player = 0,
    Enemy = 1
}

// 负责对当前关卡出战敌人进行管理
public class UnitManager
{
    private List<GameObject> UnitList = new List<GameObject>();
    // 将单位列表长度封装为UnitLiveNumber以供读取
    public int UnitLiveNumber
    {
        get
        {
            return UnitList.Count;
        }
    }

    public void UnitAddtoTail(GameObject gameObject)
    {
        UnitList.Add(gameObject);
    }

    public void UnitDelCurrent()
    {
        if (UnitList.Count > 0)
        {
            UnitList.RemoveAt(0);
        }
    }
}

//负责关卡的开始与胜负流程
public class LevelManager : MonoBehaviour
{
    // 在关卡加载流程完善前临时起向UnitManager中压入对象的作用
    [SerializeField] private GameObject[] _player;
    [SerializeField] private GameObject[] _enemy;

    public UnitManager Player = new UnitManager();
    public UnitManager Enemy = new UnitManager();

    // Start is called before the first frame update
    void Start()
    {
        // 在关卡加载流程完善前临时起向UnitManager中压入对象的作用
        for (int i = 0; i < _player.Length; i++)
        {
            Player.UnitAddtoTail(_player[i]);
        }
        for (int i = 0; i < _enemy.Length; i++)
        {
            Enemy.UnitAddtoTail(_enemy[i]);
        }
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    private void FixedUpdate()
    {
        
    }

    public void UnitReduce(UnitCamp c)
    {
        switch (c)
        {
            case UnitCamp.Player:
                Player.UnitDelCurrent();
                break;
            case UnitCamp.Enemy:
                Enemy.UnitDelCurrent();
                break;
            default:
                break;
        }
        if (Player.UnitLiveNumber == 0)
        {
            //LOSE
        }
        else if (Enemy.UnitLiveNumber == 0)
        {
            //WIN
        }
    }
}
